package com.tensquare.qa.dao;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    //方式二：执行自定义语句  通过Query注解,方法名任意
    //select * from tb_problem where id in(select problemid from tb_pl p where p.labelid = ?)

    /**
     * nativeQuery:是否执行本地查询（sql）面向表，字段  默认执行jpaql语句面向实体，属性-大小写敏感
     * @param labelId
     * @param pageable
     * @return
     */
//    @Query(nativeQuery = true, value = "select * from tb_problem where id in(select problemid from tb_pl p where p.labelid = ?1) ORDER by createtime DESC")
    @Query("select p from Problem p where id in (select problemid from PL where labelid = ?1) order by p.createtime desc ")
    public Page<Problem> findNewlist(String labelId, Pageable pageable);


    @Query("select p from Problem p where id in (select problemid from PL where labelid = ?1) order by p.reply desc ")
    public Page<Problem> findHotlist(String labelId, Pageable pageable);

    @Query("select p from Problem p where id in (select problemid from PL where labelid = ?1) and p.reply = 0 order by p.createtime desc")
    public Page<Problem> findwaitList(String labelId, Pageable pageable);

}
